package com.wlj.vo;

import com.fasterxml.jackson.annotation.JsonView;
import com.wlj.vo.view.GeneralViews;

import java.io.Serializable;

public class JsonRes <T> implements Serializable {
    private static final long serialVersionUID = 3863559687276427577L;

    @JsonView(GeneralViews.IErrorView.class)
    private boolean success = true;

    @JsonView(GeneralViews.IErrorView.class)
    public String msg;

    @JsonView(GeneralViews.INormalView.class)
    private T data;//数据

    public JsonRes() {
    }
    public JsonRes(T data, Boolean success, String message) {
        this.data = data;
        this.success = success;
        this.msg = message;
    }


    public static <T> JsonRes<T> success() {
        return new JsonRes<T>(null,true,"操作成功");
    }

    public static <T> JsonRes<T> success(T data) {
        return new JsonRes<T>(data,true,"操作成功");
    }

    public static <T> JsonRes<T> error() {
        return new JsonRes<T>(null,false,"发生未知错误");
    }

    public static <T> JsonRes<T> error(String msg) {
        return new JsonRes<T>(null,false,msg);
    }




    public boolean isSuccess() {
        return success;
    }
    public void setSuccess(boolean success) {
        this.success = success;
    }
    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
